package com.example.foobar.controller;

import com.example.foobar.business.service.DyCommentService;
import com.example.foobar.entity.DyComment;
import com.example.foobar.dao.service.DyCommentDaoService;
import com.example.foobar.vo.DyCommentQueryVo;
import lombok.extern.slf4j.Slf4j;
import com.example.foobar.param.DyCommentPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 抖音文字评论 控制器
 *
 * @author 郑英奔
 * @since 2021-07-23
 */
@Slf4j
@RestController
@RequestMapping("/dyComment")
@Module("foobar")
@Api(value = "抖音文字评论API", tags = {"抖音文字评论"})
public class DyCommentController extends BaseController {

    @Autowired
    private DyCommentService dyCommentService;

    /**
     * 添加抖音文字评论
     */
    @PostMapping("/add")
    @OperationLog(name = "添加抖音文字评论", type = OperationLogType.ADD)
    @ApiOperation(value = "添加抖音文字评论", response = ApiResult.class)
    public ApiResult<Boolean> addDyComment(@Validated(Add.class) @RequestBody DyComment dyComment) throws Exception {
        boolean flag = dyCommentService.saveDyComment(dyComment);
        return ApiResult.result(flag);
    }

    /**
     * 修改抖音文字评论
     */
    @PostMapping("/update")
    @OperationLog(name = "修改抖音文字评论", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改抖音文字评论", response = ApiResult.class)
    public ApiResult<Boolean> updateDyComment(@Validated(Update.class) @RequestBody DyComment dyComment) throws Exception {
        boolean flag = dyCommentService.updateDyComment(dyComment);
        return ApiResult.result(flag);
    }

    /**
     * 删除抖音文字评论
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除抖音文字评论", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除抖音文字评论", response = ApiResult.class)
    public ApiResult<Boolean> deleteDyComment(@PathVariable("id") Long id) throws Exception {
        boolean flag = dyCommentService.deleteDyComment(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取抖音文字评论详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "抖音文字评论详情", type = OperationLogType.INFO)
    @ApiOperation(value = "抖音文字评论详情", response = DyComment.class)
    public ApiResult<DyComment> getDyComment(@PathVariable("id") Long id) throws Exception {
        DyComment dyComment = dyCommentService.getById(id);
        return ApiResult.ok(dyComment);
    }

    /**
     * 抖音文字评论分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "抖音文字评论分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "抖音文字评论分页列表", response = DyComment.class)
    @RequiresPermissions("sys:dy-comment:page")
    public ApiResult<Paging<DyCommentQueryVo>> getDyCommentPageList(@Validated @RequestBody DyCommentPageParam dyCommentPageParam) throws Exception {
        Paging<DyCommentQueryVo> paging = dyCommentService.getDyCommentPageList(dyCommentPageParam);
        return ApiResult.ok(paging);
    }

}

